<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 传统面向对象  继承
        // [1,2,3]
        class MovieCollection extends Array {
            constructor(name, ...items) { // ... reset 收起来
                super(...items); // 展开运算符  父类的构造函数 调用父类方法 
                this.name = name;
            }
            add(movie) {
                this.push(movie);
            }
            topRated(limit = 10) { // 默认值
                return this.sort((a, b) => a.stars - b.stars).slice(0, limit)
            }
        }
        const movies = new MovieCollection(`Web\'s Fav Movies`, // \ 转意
            { name: 'Bee Movie', stars: 6 },
            { name: 'Star War Trek', stars: 1},
            { name: 'Virgin Sunicids', stars: 7},
            { name: 'King of the Road', stars: 8},

        )
        movies.add({ name: '战狼', stars: 9 });
        console.log( movies.topRated(3) )
    </script>
</body>
</html>